﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 剧情设计器2._0
{
    [Serializable]
    public class Event
    {
        //事件的名称
        public string name = "";
        //事件中包含的动作
        public List<Action> actions = new List<Action>();

        public override int GetHashCode()
        {
            int code = name.GetHashCode();
            foreach (Action action in actions)
                code += action.GetHashCode();
            return code;
        }

        public int getTime()
        {
            if (actions.Count != 0)
                return actions.Count;
            else return 1;
        }

        public void draw(Graphics g, int x, int y)
        {
            Pen pen = new Pen(Color.Blue);
            int w;
            if (actions.Count != 0)
                w = (112 + 6) * actions.Count - 2;
            else w = 112 + 6 - 2;
            const int h = 68;
            int textHeight = 10;

            g.DrawRectangle(pen, x, y, w, h);
            g.DrawString(name, new Font("微软雅黑", textHeight), pen.Brush, new PointF(x + 4, y + 1));
            for(int i = 0; i < actions.Count; i++)
            {
                actions[i].draw(g, x + 2 + i * (112 + 6), y + 18);
            }
        }

        public int getW()
        {
            if (actions.Count != 0)
                return 118 * actions.Count;
            else return 118;
        }
    }
}
